package com.word.Controller;

import com.utils.APIRespones;
import com.word.Service.WordService;
import com.word.entity.word;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/words")
public class WordController {

    @Autowired
    private WordService wordService;

    @PostMapping("/push")
    public void addOrUpdateWord(@RequestBody word word) {
        wordService.addOrUpdateWord(word);
    }
    @GetMapping("/list")
    public APIRespones getAllWords() {
        List<word> words = wordService.getAllWords();
        if (words != null && !words.isEmpty()) {
            Map<String, Object> data = new HashMap<>();
            data.put("words", words);
            return APIRespones.success(data);
        } else {
            return APIRespones.failure("No words found in the database.");
        }
    }
}
